package com.mask.hdfs;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;

import java.io.IOException;
import java.net.URI;

/**
 * ClassName TestHdfs
 * Create by hx
 * Date 2021/9/4 2:51 下午
 */

public class TestHdfs {
    public Configuration conf = null;
    public FileSystem fs = null;


    // C/S
    @Before
    public void connect() throws IOException, InterruptedException {
        conf = new Configuration(true); //加载编译的配置文件
        fs = FileSystem.get(conf);
        fs = FileSystem.get(URI.create("hdfs://mycluster/"),conf,"root");
    }

    @Test
    public void mkdir() throws IOException {
        Path dir = new Path("/mask");
        //如果文件删除则删除该文件
        if (fs.exists(dir)){
            fs.delete(dir,true);
        }
        fs.mkdirs(dir);
    }

    @After
    public void close() throws IOException {
        fs.close();
    }
}
